package com.ruoyi.loan.loan.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.loan.loan.utils.AliyunOssUtil;
import com.ruoyi.loan.loan.utils.HttpUtils;
import com.ruoyi.loan.loan.utils.OcrIdcardUtils;
import com.ruoyi.loan.loan.utils.pojo.IdCodeBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.codec.binary.Base64;

/**
 * @author 杰少
 * @version 6.6.6
 * @description: TODO
 * @date 2023/1/15 14:32
 */
@Slf4j
@Api("loanFile-server")
@RestController
@RequestMapping("/loanFile")
public class TbLoanFileController {

    /**
     * 身份证上传
     * @param file
     * @return
     */
    @ApiOperation("身份证上传")
    @PostMapping("/sendFile")
    public AjaxResult sendFile(@RequestParam("file")MultipartFile file){

        AliyunOssUtil oss = AliyunOssUtil.OSS();
        String url = oss.upload(file);
        // 判断上传是否成功
        if(url == null){
            log.error("上传失败");
            return AjaxResult.error("上传失败");
        }

        return AjaxResult.success(url);
    }

}
